/*
 * Powered By [Frank-Liz-Lee]
 * Copyright(C) 2012-2021 Liz Company
 * All rights reserved.
 * -----------------------------------------------
 */

package com.liz.springCloudAlibaba.provider.model;

import java.io.Serializable;
import java.util.List;

/**
 * 通用分页组件类
 * Created by lizhou on 2016/7/21
 */
public class Pagination<T> implements Serializable {

    private static final long serialVersionUID = -1267803561459511298L;

    /* 默认每页显示数据条数 */
    public static final int DEFAULT_PAGE_SIZE = 15;

    /* 数据总条数 */
    private int total;

    /* 数据总页数 */
    private int totalPage;

    /* 当前页数 */
    private int pageNo = 1;

    /* 每页显示数据条数  */
    private int pageSize = 15;

    /* 是否需要分页查询的标示 */
    private boolean paginationFlag = false;

    /* 分页查询后的数据 */
    private List<T> resultList;

    public Pagination() {
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public boolean isPaginationFlag() {
        return paginationFlag;
    }

    public void setPaginationFlag(boolean paginationFlag) {
        this.paginationFlag = paginationFlag;
    }

    public List<T> getResultList() {
        return resultList;
    }

    public void setResultList(List<T> resultList) {
        this.resultList = resultList;
    }

    public int getTotalPage() {
        this.totalPage = (int)Math.ceil((double)this.total / (double)this.pageSize);
        return this.totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    @Override
    public String toString() {
        return "Pagination{" +
                "total=" + total +
                ", totalPage=" + totalPage +
                ", pageNo=" + pageNo +
                ", pageSize=" + pageSize +
                ", paginationFlag=" + paginationFlag +
                ", resultList=" + resultList +
                '}';
    }
}
